﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Security.Principal;

namespace Mocola.Common
{
    public class CustomIdentity : IIdentity
    {
        private FormsAuthenticationTicket ticket;
        private HttpContext context = HttpContext.Current;

        public CustomIdentity(FormsAuthenticationTicket ticket)
        {
            this.ticket = ticket;
        }

        public string AuthenticationType
        {
            get { return "Custom"; }
        }

        public bool IsAuthenticated
        {
            get { return true; }
        }

        public string Name
        {
            get
            {
                return ticket.Name;
            }
        }

        public string FullName
        {
            get { return SiteUser.GetUser(this.Name).FullName; }
        }

        public FormsAuthenticationTicket Ticket
        {
            get { return ticket; }
        }

        public int UserID
        {
            get { return SiteUser.GetUser(this.Name).UserID; }
        }

        public string UserName
        {
            get { return ticket.Name; }
        }

        public string UserPwd
        {
            get { return SiteUser.GetUser(this.Name).UserPwd; }
        }

        public bool UserSex
        {
            get { return SiteUser.GetUser(this.Name).UserSex; }
        }

        public int Status
        {
            get { return SiteUser.GetUser(this.Name).Status; }
        }

        public int LoginTimes
        {
            get { return SiteUser.GetUser(this.Name).LoginTimes; }
        }

        public DateTime LastLoginTime
        {
            get { return SiteUser.GetUser(this.Name).LastLoginTime; }
        }

        public int RoleID
        {
            get { return SiteUser.GetUser(this.Name).RoleID; }
        }

        public string RolesName
        {
            get { return SiteUser.GetUser(this.Name).RolesName; }
        }

        public string Email
        {
            get { return SiteUser.GetUser(this.Name).Email; }
        }
    }
}

